/**
 * 
 */
package org.statewalker.fsm.providers;

import org.statewalker.fsm.FsmProcess;

/**
 * @author kotelnikov
 */
public abstract class FsmStateProvider<SK, S, EK, E>
    extends
    AbstractFsmStateProvider<SK, S, EK, E> {

    private IFsmTransitionsRegistry<SK, EK> fRegistry;

    protected FsmStateProvider(
        FsmTransitionsConst<SK, EK> info,
        IFsmTransitionsRegistry<SK, EK> registry) {
        super(info);
        fRegistry = registry;
    }

    @Override
    protected EK getParentEventKey(EK eventKey) {
        EK root = fInfo.getRootEventKey();
        if (root.equals(eventKey))
            return null;
        return root;
    }

    @Override
    protected IFsmTransitions<SK, EK> getTransitions(FsmProcess<S, E> process) {
        S parent = process.getCurrentState();
        if (parent == null)
            return null;
        SK parentKey = getStateKey(parent);
        IFsmTransitions<SK, EK> transitions = fRegistry
            .getTransitions(parentKey);
        return transitions;
    }
}
